package com.atguigu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Date:2020/9/28
 * Author:ybc
 * Description:
 */
@Controller
public class ScopeController {

    //使用servletApi在请求域中共享数据
    /*@RequestMapping("/testScope")
    public String testScope(HttpServletRequest request){
        request.setAttribute("scope", "你好");
        return "success";
    }*/

    //通过ModelAndView实现功能
    /*@RequestMapping("/testScope")
    public ModelAndView testScope(){
        ModelAndView mav = new ModelAndView();
        //1、向请求域共享数据
        mav.addObject("scope", "ModelAndView");
        //2、设置视图名称，实现页面跳转
        mav.setViewName("success");
        return mav;
    }*/

    //通过Model向请求域中共享数据
    /*@RequestMapping("/testScope")
    public String testScope(Model model){
        model.addAttribute("scope", "modelScope");
        return "success";
    }*/

    @RequestMapping("/testScope")
    public String testScope(Map<String, Object> map){
        map.put("scope", "mapScope");
        return "success";
    }

}
